This report analyzes the operation of MBTA’s subway, bus, and ferry. To limit the project size, I picked a week randomly from the past 12 months as my dataset. For data on the subway, the first month is Oct. 2021 and the last month is Sept. 2022. It is the same as the data of the bus. For the ferry, the first month is Jan. 2021, and the last month is Dec.2021.
library(tidyverse)
library(ggplot2)
library(leaflet)
library(rgdal)
library(sf)
library(magrittr)
library(viridis)
library(hrbrthemes)
##import subway data
HR_selected<-read.csv("~/Desktop/HR_selected.csv")
LR_selected<-read.csv("~/Desktop/LR_selected.csv")
##import data for mapping
MBTA_icon <- makeIcon(
iconUrl = "https://upload.wikimedia.org/wikipedia/commons/thumb/6/64/MBTA.svg/240px-MBTA.svg.png",iconWidth = 15, iconHeight = 15)
MBTA_sub <- readOGR(dsn="~/desktop/mbta_rapid_transit", layer="MBTA_ARC")
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/yirong/Desktop/mbta_rapid_transit", layer: "MBTA_ARC"
## with 141 features
## It has 4 fields
MBTA_sub <- spTransform(MBTA_sub, CRS("+proj=longlat +ellps=GRS80"))
MBTA_sub_stops <- readOGR(dsn="~/desktop/mbta_rapid_transit", layer="MBTA_NODE")
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/yirong/Desktop/mbta_rapid_transit", layer: "MBTA_NODE"
## with 170 features
## It has 4 fields
MBTA_sub_stops <- spTransform(MBTA_sub_stops, CRS("+proj=longlat +ellps=GRS80"))
MBTA_bus <- readOGR(dsn="~/desktop/mbtabus", layer="MBTABUSROUTES_ARC")
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/yirong/Desktop/mbtabus", layer: "MBTABUSROUTES_ARC"
## with 923 features
## It has 11 fields
## Integer64 fields read as strings: CTPS_ROU_2
MBTA_bus <- spTransform(MBTA_bus, CRS("+proj=longlat +ellps=GRS80"))
MBTA_bus_stops <- readOGR(dsn="~/desktop/mbtabus", layer="MBTABUSSTOPS_PT")
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/yirong/Desktop/mbtabus", layer: "MBTABUSSTOPS_PT"
## with 7810 features
## It has 4 fields
## Integer64 fields read as strings: STOP_ID
MBTA_bus_stops <- spTransform(MBTA_bus_stops, CRS("+proj=longlat +ellps=GRS80"))
MBTA_ferry <- readOGR(dsn="~/desktop/Ferry_Routes", layer="Ferry_Routes")
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/yirong/Desktop/Ferry_Routes", layer: "Ferry_Routes"
## with 41 features
## It has 14 fields
MBTA_ferry <- spTransform(MBTA_ferry, CRS("+proj=longlat +ellps=GRS80"))
MBTA_ferry_stops <- readOGR(dsn="~/desktop/Seaports", layer="Seaports")
## OGR data source with driver: ESRI Shapefile
## Source: "/Users/yirong/Desktop/Seaports", layer: "Seaports"
## with 30 features
## It has 14 fields
MBTA_ferry_stops <- spTransform(MBTA_ferry_stops, CRS("+proj=longlat +ellps=GRS80"))
##import bus data
BUS_selected<-read.csv("~/Desktop/BUS_selected.csv")
##import ferry data
Ferry_selected<-read.csv("~/Desktop/Ferry_selected.csv")
I used three leaflet plots to display the routes and stops of the MBTA subway, bus, and ferry. MBTA Subway routes and stops
pal <- colorFactor(palette = c('blue','green','orange','red','grey'),
domain = c('BLUE','GREEN','ORANGE','RED','SILVER'))
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addPolylines(data = MBTA_sub, color=~pal(LINE)) %>%
addMarkers(data=MBTA_sub_stops,icon=MBTA_icon)
MBTA Bus routes and stops
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
addPolylines(data = MBTA_bus, color="orange") %>%
addMarkers(data=MBTA_bus_stops,icon=MBTA_icon)